package com.souku.finance.application.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.souku.finance.application.R;
import com.souku.finance.application.bean.InviteListBean;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.widget.CircleViewHome;
import com.souku.finance.application.widget.CircleViewList;
import com.souku.finance.application.widget.MyTextView;

import java.util.List;

/**
 * Created by Android on 2016/12/19.
 */
public class InviteListAdapter extends BaseAdapter {

    private List<InviteListBean.DataBean> list;
    private Activity context;

    public InviteListAdapter(Activity context, List<InviteListBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_invitelist, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.circle.setStoke(context);
        viewHolder.circle1.setStoke(context);
        InviteListBean.DataBean bean = list.get(i);

        if (bean.getIsCurrentDeal().equals("1")) {
            viewHolder.linearlayoutTop.setVisibility(View.VISIBLE);
            viewHolder.linearlayoutBottom.setVisibility(View.GONE);
            viewHolder.circle.setPrograss(Double.parseDouble(bean.getRate()), Double.parseDouble(bean.getRate()), viewHolder.tvCircle, true);
        } else {
            viewHolder.linearlayoutTop.setVisibility(View.GONE);
            viewHolder.linearlayoutBottom.setVisibility(View.VISIBLE);
            viewHolder.circle1.setPrograss(Integer.parseInt(bean.getInvestmentAmount()), Integer.parseInt(bean.getBorrowAmount()), viewHolder.tvCircle1);
            viewHolder.tv1.setText(bean.getRate());
            if (bean.getDealDateType().equals("1")) {
                viewHolder.tv2.setText(Integer.parseInt(bean.getDealDate()) * 30 + "");
            } else {
                viewHolder.tv2.setText(Integer.parseInt(bean.getDealDate()) + "");
            }
        }
        if (bean.getIsNew().equals("0")) {//MyTextUtil.isEmpty(bean.getActivityName()
            viewHolder.tv3.setVisibility(View.GONE);
        } else {
            viewHolder.tv3.setVisibility(View.VISIBLE);
            viewHolder.tv3.setText("新客专享");
//            viewHolder.tv3.setText(bean.getActivityName());
        }
        viewHolder.tv4.setText(bean.getDealName());
        viewHolder.tvMinmoney.setText(MyTextUtil.setMoneyToElement(bean.getMinInvestment()));
        return view;
    }


    static class ViewHolder {
        protected CircleViewHome circle;
        protected TextView tvCircle;
        protected LinearLayout linearlayoutTop;
        protected MyTextView tv1;
        protected MyTextView tv2;
        protected CircleViewList circle1;
        protected TextView tvCircle1;
        protected LinearLayout linearlayoutBottom;
        protected TextView tv3;
        protected TextView tv4;
        protected TextView tvMinmoney;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            circle = (CircleViewHome) rootView.findViewById(R.id.circle);
            tvCircle = (TextView) rootView.findViewById(R.id.tv_circle);
            linearlayoutTop = (LinearLayout) rootView.findViewById(R.id.linearlayout_top);
            tv1 = (MyTextView) rootView.findViewById(R.id.tv_1);
            tv2 = (MyTextView) rootView.findViewById(R.id.tv_2);
            circle1 = (CircleViewList) rootView.findViewById(R.id.circle1);
            tvCircle1 = (TextView) rootView.findViewById(R.id.tv_circle1);
            linearlayoutBottom = (LinearLayout) rootView.findViewById(R.id.linearlayout_bottom);
            tv3 = (TextView) rootView.findViewById(R.id.tv_3);
            tv4 = (TextView) rootView.findViewById(R.id.tv_4);
            tvMinmoney = (TextView) rootView.findViewById(R.id.tv_minmoney);
        }
    }
}
